package dl.bukkit.myststus.task;

import dl.bukkit.myststus.MyStatus;
import dl.bukkit.myststus.library.container.ListContainer;
import dl.bukkit.myststus.loader.Loader;
import dl.bukkit.myststus.loader.Register;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;

public class TaskManager implements Loader {

    private final MyStatus plugin;
    private final ListContainer<MainTask> container;

    public TaskManager(MyStatus plugin) {
        this.plugin = plugin;
        this.container = new ListContainer<>(new ArrayList<>(), MyStatus.class);
    }

    @Override
    public void onLoad() {
        container.register(Task.class, plugin);
    }

    @Override
    public void staring() {
        container.getList().stream().filter(MainTask::isRegister).forEach(MainTask::runTaskAsynchronously);
    }

    protected static abstract class MainTask extends BukkitRunnable implements Register {
        public abstract void runTaskAsynchronously();
    }
}
